<?php
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/stock/stock.css');
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/orderlog.css');
$gridCss = Yii::app()->baseUrl . '/css/stock/grid/fip-style.css'; //Update stock grid 's style/css here
$this->breadcrumbs = array(
    'Portfolios' => array('index'),
    'Manage',
);

include "menu.php";

//Buy Log
$tickers = Stock::model()->getAllCompany();
$buyLogDataProvider = $buylog->search();
foreach ($buyLogDataProvider->getData() as $row) {
    $row->date = date("d/m/Y", strtotime($row->date));
    $row->amount_m = number_format($row->amount_m, 2, '.', ',');
    $row->price_m = number_format($row->price_m, 2, '.', ',');
    $row->quantity_m = number_format($row->quantity_m, 2, '.', ',');
}

//Sell Log
$sellLogDataProvider = $selllog->search();
foreach ($sellLogDataProvider->getData() as $row) {
    $row->date = date("d/m/Y", strtotime($row->date));
    $row->amount_m = number_format($row->amount_m, 2, '.', ',');
    $row->price_m = number_format($row->price_m, 2, '.', ',');
    $row->quantity_m = number_format($row->quantity_m, 2, '.', ',');
}

//Dividend in Share
$divInShareDataProvider = $divinshare->search();
foreach ($divInShareDataProvider->getData() as $row) {
    $row->date = date("d/m/Y", strtotime($row->date));
    $row->amount_m = number_format($row->amount_m, 2, '.', ',');
    $row->price_m = number_format($row->price_m, 2, '.', ',');
    $row->quantity_m = number_format($row->quantity_m, 2, '.', ',');
}

//Dividend in Cash
$divInCashDataProvider = $divincash->search();
foreach ($divInCashDataProvider->getData() as $row) {
    $row->date = date("d/m/Y", strtotime($row->date));
    $row->money = number_format($row->money, 2, '.', ',');
}

//Split
$splitDataProvider = $split->search();
foreach ($splitDataProvider->getData() as $row) {
    $row->date = date("d/m/Y", strtotime($row->date));
    $row->amount_m = number_format($row->amount_m, 2, '.', ',');
    $row->price_m = number_format($row->price_m, 2, '.', ',');
    $row->quantity_m = number_format($row->quantity_m, 2, '.', ',');
}

//Option
$optionDataProvider = $option->search();
foreach ($optionDataProvider->getData() as $row) {
    $row->date = date("d/m/Y", strtotime($row->date));
    $row->amount_m = number_format($row->amount_m, 2, '.', ',');
    $row->price_m = number_format($row->price_m, 2, '.', ',');
    $row->quantity_m = number_format($row->quantity_m, 2, '.', ',');
}

//Update datepicker after gridview update
$afterUpdate = "js:function(id, data) {jQuery('.datepker').datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true, yearRange: '-20:+20', constraint: true});}";
?>
<div id="log">
<h3>Matched buy order</h3>


<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'buylog-grid',
    'dataProvider' => $buyLogDataProvider,
    'filter' => $buylog,
    'cssFile' => $gridCss,
    'afterAjaxUpdate' => $afterUpdate,
    'pager' => array('cssFile' => $gridCss),
    'columns' => array(
        array(
            'name' => 'Date',
            'value' => '$data->date',
            'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $buylog,
                'attribute' => 'date',
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => 'buylog-date',
                    'class' => 'datepker',
                ),
            ),true),
            ),
        array(
            'name' => 'companyID',
            'value' => '$data->company->ticket', // in the companyID column, we get the ticker of the Company instead of the interger id
            'htmlOptions' => array('class' => 'ticket'), //this line only use for css
            'filter' => $tickers, //Instead of a input[type=text] filter, this line will make a dropdownlist filter for Tickers
        ),
        array(
            'name' => 'quantity_m',
            'value' => '$data->quantity_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'price_m',
            'value' => '$data->price_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'amount_m',
            'value' => '$data->amount_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'header' => 'Edit',
            'class' => 'CButtonColumn',
            'template' => '{update} {delete}', //update and delete buttons
            'buttons' => array(
                'update' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/update.png',
                ),
                'delete' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/delete.png',
                ),
            ),
        ),
    ),
));
?>
<br />
<h3>Matched sell order</h3>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'selllog-grid',
    'dataProvider' => $sellLogDataProvider,
    'filter' => $selllog,
    'cssFile' => $gridCss,
    'afterAjaxUpdate' => $afterUpdate,
    'pager' => array('cssFile' => $gridCss),
    'columns' => array(
        array(
            'name' => 'Date',
            'value' => '$data->date',
            'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $selllog,
                'attribute' => 'date',
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => 'sellog-date',
                    'class' => 'datepker',
                ),
            ),true),
            ),
        array(
            'name' => 'companyID',
            'value' => '$data->company->ticket', // in the companyID column, we get the ticker of the Company instead of the interger id
            'htmlOptions' => array('class' => 'ticket'), //this line only use for css
            'filter' => $tickers, //Instead of a input[type=text] filter, this line will make a dropdownlist filter for Tickers
        ),
        array(
            'name' => 'quantity_m',
            'value' => '$data->quantity_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'price_m',
            'value' => '$data->price_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'amount_m',
            'value' => '$data->amount_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'header' => 'Edit',
            'class' => 'CButtonColumn',
            'template' => '{update} {delete}', //update and delete buttons
            'buttons' => array(
                'update' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/update.png',
                ),
                'delete' => array(
                    'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/delete.png',
                ),
            ),
        ),
    ),
));
?>
</div>
<div id="other">
    <h3>Share Dividend</h3>
    <?php
    $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'dividendinshare-grid',
        'dataProvider' => $divInShareDataProvider,
        'filter' => $divinshare,
        'cssFile' => $gridCss,
    'afterAjaxUpdate' => $afterUpdate,
        'pager' => array('cssFile' => $gridCss),
    'columns' => array(
        array(
            'name' => 'Date',
            'value' => '$data->date',
            'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $divinshare,
                'attribute' => 'date',
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array('id'=>'divinshare-date',
                    'class' => 'datepker',)
                ), true),
        ),
            array(
                'name' => 'companyID',
                'value' => '$data->company->ticket', // in the companyID column, we get the ticker of the Company instead of the interger id
                'htmlOptions' => array('class' => 'ticket'), //this line only use for css
                'filter' => $tickers, //Instead of a input[type=text] filter, this line will make a dropdownlist filter for Tickers
            ),
            array(
            'name' => 'quantity_m',
            'value' => '$data->quantity_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'price_m',
            'value' => '$data->price_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'amount_m',
            'value' => '$data->amount_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
            array(
                'header' => 'Edit',
                'class' => 'CButtonColumn',
                'template' => '{update} {delete}', //update and delete buttons
                'buttons' => array(
                    'update' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/update.png',
                    ),
                    'delete' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/delete.png',
                    ),
                ),
            ),
        ),
    ));
    ?>
    <h3>Cash Dividend</h3>
    <?php
    $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'divincash-grid',
        'dataProvider' => $divInCashDataProvider,
        'filter' => $divincash,
        'cssFile' => $gridCss,
    'afterAjaxUpdate' => $afterUpdate,
        'pager' => array('cssFile' => $gridCss),
        'columns' => array(
            array(
            'name' => 'Date',
            'value' => '$data->date',
            'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $divincash,
                'attribute' => 'date',
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => 'divincash-date',
                    'class' => 'datepker',
                ),
            ),true),
            ),
            array(
                'name' => 'companyID',
                'value' => '$data->company->ticket', // in the companyID column, we get the ticker of the Company instead of the interger id
                'htmlOptions' => array('class' => 'ticket'), //this line only use for css
                'filter' => $tickers, //Instead of a input[type=text] filter, this line will make a dropdownlist filter for Tickers
            ),
            array(
            'name' => 'money',
            'value' => '$data->money',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
            //'type',
            //'status',
            //'portfolionameID',
            array(
                'header' => 'Edit',
                'class' => 'CButtonColumn',
                'template' => '{update} {delete}', //update and delete buttons
                'buttons' => array(
                    'update' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/update.png',
                    ),
                    'delete' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/delete.png',
                    ),
                ),
            ),
        ),
    ));
    ?>
    <h3>Stock Split</h3>
    <?php
    $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'split-grid',
        'dataProvider' => $splitDataProvider,
        'filter' => $split,
        'cssFile' => $gridCss,
    'afterAjaxUpdate' => $afterUpdate,
        'pager' => array('cssFile' => $gridCss),
        'columns' => array(
            array(
            'name' => 'Date',
            'value' => '$data->date',
            'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $split,
                'attribute' => 'date',
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => 'split-date',
                    'class' => 'datepker',
                ),
            ),true),
            ),
            array(
                'name' => 'companyID',
                'value' => '$data->company->ticket', // in the companyID column, we get the ticker of the Company instead of the interger id
                'htmlOptions' => array('class' => 'ticket'), //this line only use for css
                'filter' => $tickers, //Instead of a input[type=text] filter, this line will make a dropdownlist filter for Tickers
            ),
            array(
            'name' => 'quantity_m',
            'value' => '$data->quantity_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'price_m',
            'value' => '$data->price_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'amount_m',
            'value' => '$data->amount_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
            array(
                'header' => 'Edit',
                'class' => 'CButtonColumn',
                'template' => '{update} {delete}', //update and delete buttons
                'buttons' => array(
                    'update' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/update.png',
                    ),
                    'delete' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/delete.png',
                    ),
                ),
            ),
        ),
    ));
    ?>
    <h3>Stock Rights</h3>
    <?php
    $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'portfolionew-grid',
        'dataProvider' => $optionDataProvider,
        'filter' => $option,
        'cssFile' => $gridCss,
    'afterAjaxUpdate' => $afterUpdate,
        'pager' => array('cssFile' => $gridCss),
        'columns' => array(
            array(
            'name' => 'Date',
            'value' => '$data->date',
            'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $option,
                'attribute' => 'date',
                // additional javascript options for the date picker plugin
                'options' => array(
                    'showAnim' => 'fold',
                    'dateFormat' => 'dd/mm/yy',
                    'changeMonth' => true,
                    'changeYear' => true,
                    'yearRange' => '-20:+20',
                    'constrainInput' => true,
                ),
                'htmlOptions' => array(
                    'id' => 'option-date',
                    'class' => 'datepker',
                ),
            ),true),
            ),
            array(
                'name' => 'companyID',
                'value' => '$data->company->ticket', // in the companyID column, we get the ticker of the Company instead of the interger id
                'htmlOptions' => array('class' => 'ticket'), //this line only use for css
                'filter' => $tickers, //Instead of a input[type=text] filter, this line will make a dropdownlist filter for Tickers
            ),
            array(
            'name' => 'quantity_m',
            'value' => '$data->quantity_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'price_m',
            'value' => '$data->price_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
        array(
            'name' => 'amount_m',
            'value' => '$data->amount_m',
            'htmlOptions' => array(
                'class' => 'number',
            ),
        ),
            array(
                'header' => 'Edit',
                'class' => 'CButtonColumn',
                'template' => '{update} {delete}', //update and delete buttons
                'buttons' => array(
                    'update' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/update.png',
                    ),
                    'delete' => array(
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/stock-grid/set02/delete.png',
                    ),
                ),
            ),
        ),
    ));
    ?>
</div>
<div class="clear"></div>
